package com.guigu.pd.base.controller;

import java.util.Arrays;
import java.util.Map;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.guigu.pd.base.entity.TruckLicenseEntity;
import com.guigu.pd.base.service.TruckLicenseService;
import com.guigu.common.utils.PageUtils;
import com.guigu.common.utils.R;



/**
 * 车辆行驶证表
 *
 * @author deyran
 * @email deyran@gmail.com
 * @date 2022-07-19 19:09:01
 */
@RestController
@RequestMapping("base/trucklicense")
public class TruckLicenseController {
    @Autowired
    private TruckLicenseService truckLicenseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("base:trucklicense:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = truckLicenseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("base:trucklicense:info")
    public R info(@PathVariable("id") String id){
		TruckLicenseEntity truckLicense = truckLicenseService.getById(id);

        return R.ok().put("truckLicense", truckLicense);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("base:trucklicense:save")
    public R save(@RequestBody TruckLicenseEntity truckLicense){
		truckLicenseService.save(truckLicense);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("base:trucklicense:update")
    public R update(@RequestBody TruckLicenseEntity truckLicense){
		truckLicenseService.updateById(truckLicense);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("base:trucklicense:delete")
    public R delete(@RequestBody String[] ids){
		truckLicenseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    @GetMapping("/getbyruckid/{id}")
    public TruckLicenseEntity getbytruckId(@PathVariable("id") String id){
        QueryWrapper<TruckLicenseEntity> queryWrapper = new QueryWrapper<TruckLicenseEntity>();
        queryWrapper.eq("truck_id",id);
        TruckLicenseEntity truckLicense = truckLicenseService.getOne(queryWrapper);

        return truckLicense;
    }

}
